package com.ruoyi.web.controller.system.studnts;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.students.domain.students;
import com.ruoyi.students.service.IstudentsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学生信息Controller
 * 
 * @author ruoyi
 * @date 2021-05-11
 */
@Controller
@RequestMapping("/studens/students")
public class studentsController extends BaseController
{
    private String prefix = "studens/students";

    @Autowired
    private IstudentsService studentsService;

    @RequiresPermissions("studens:students:view")
    @GetMapping()
    @ResponseBody
    public String students()
    {
        return prefix + "/students";
    }

    /**
     * 查询学生信息列表
     */
    @RequiresPermissions("studens:students:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(students students)
    {
        startPage();
        List<students> list = studentsService.selectstudentsList(students);
        return getDataTable(list);
    }

    /**
     * 导出学生信息列表
     */
    @RequiresPermissions("studens:students:export")
    @Log(title = "学生信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(students students)
    {
        List<students> list = studentsService.selectstudentsList(students);
        ExcelUtil<students> util = new ExcelUtil<students>(students.class);
        return util.exportExcel(list, "学生信息数据");
    }

    /**
     * 新增学生信息
     */
    @GetMapping("/add")
    @ResponseBody
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学生信息
     */
    @RequiresPermissions("studens:students:add")
    @Log(title = "学生信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(students students)
    {
        return toAjax(studentsService.insertstudents(students));
    }

    /**
     * 修改学生信息
     */
    @GetMapping("/edit/{sid}")
    @ResponseBody
    public String edit(@PathVariable("sid") Long sid, ModelMap mmap)
    {
        students students = studentsService.selectstudentsById(sid);
        mmap.put("students", students);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生信息
     */
    @RequiresPermissions("studens:students:edit")
    @Log(title = "学生信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(students students)
    {
        return toAjax(studentsService.updatestudents(students));
    }

    /**
     * 删除学生信息
     */
    @RequiresPermissions("studens:students:remove")
    @Log(title = "学生信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(studentsService.deletestudentsByIds(ids));
    }
}
